#include"commm.hpp"

int main(){
    //创建命名管道
    bool r = createFifo(NAMED_PIPE);
    assert(r);
    (void)r;

    //服务端用来读取数据
    int rfd = open(NAMED_PIPE,O_RDONLY);
    if(rfd < 0){
        exit(1);
    }

    char buffer[1024];
    //一直读取数据
    while(true){
        ssize_t s = read(rfd,buffer,sizeof(buffer)-1);
        if(s > 0){
            buffer[s] = 0;
            cout<<"client->server# "<<buffer<<endl;
        }else if(s == 0){//如果读取到0，就说明读取到文件缓冲区的结尾了
            cout<<"client quit ,me too "<<endl;
            break;
        }else{
            cout<<"err string: "<<strerror(errno)<<endl;
            break;
        }
    }

    close(rfd);


    //关闭命名管道
    sleep(10);
    removeFifo(NAMED_PIPE);

    return 0;
}